<!DOCTYPE html>
<!--[if IE 8]> <html lang="en" class="ie8 no-js"> <![endif]-->
<!--[if IE 9]> <html lang="en" class="ie9 no-js"> <![endif]-->
<!--[if !IE]><!-->
<html lang="en" class="no-js">
<!--<![endif]-->

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>新建卖盘池</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta content="width=device-width, initial-scale=1" name="viewport">
<meta content="" name="description">
<meta content="" name="author">
<link href="${request.getContextPath()}/Public/assets/admin/css/css.css" rel="stylesheet" type="text/css">
<link href="${request.getContextPath()}/Public/assets/global/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<link href="${request.getContextPath()}/Public/assets/global/plugins/simple-line-icons/simple-line-icons.min.css" rel="stylesheet" type="text/css">
<link href="${request.getContextPath()}/Public/assets/global/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css">
<link href="${request.getContextPath()}/Public/assets/global/plugins/uniform/css/uniform.default.css" rel="stylesheet" type="text/css">
<link href="${request.getContextPath()}/Public/assets/global/plugins/jquery-ui/jquery-ui.min.css" rel="stylesheet" type="text/css">

<link href="${request.getContextPath()}/Public/assets/global/css/components-rounded.css" id="style_components" rel="stylesheet" type="text/css">
<link href="${request.getContextPath()}/Public/assets/global/css/plugins.css" rel="stylesheet" type="text/css">
<link href="${request.getContextPath()}/Public/assets/admin/css/layout.css" rel="stylesheet" type="text/css">
<link href="${request.getContextPath()}/Public/assets/admin/css/themes/default.css" rel="stylesheet" type="text/css" id="style_color">
<link href="${request.getContextPath()}/Public/assets/admin/css/custom.css" rel="stylesheet" type="text/css">
<link href="${request.getContextPath()}/Public/assets/global/plugins/bootstrap-datepicker/css/bootstrap-datepicker.min.css" rel="stylesheet" type="text/css">
<link href="${request.getContextPath()}/Public/assets/admin/css/common.css" rel="stylesheet" type="text/css">



<link rel="shortcut icon" href="${request.getContextPath()}/Public/favicon.ico">
<!--[if lt IE 9]>
<script src="${request.getContextPath()}/Public/assets/global/plugins/respond.min.js"></script>
<script src="${request.getContextPath()}/Public/assets/global/plugins/excanvas.min.js"></script>
<![endif]-->
<script src="${request.getContextPath()}/Public/assets/global/plugins/jquery.min.js" type="text/javascript"></script>
<script src="${request.getContextPath()}/Public/assets/global/plugins/jquery-migrate.min.js" type="text/javascript"></script>
<script src="${request.getContextPath()}/Public/assets/global/plugins/jquery-ui/jquery-ui.min.js" type="text/javascript"></script>
<script src="${request.getContextPath()}/Public/assets/global/plugins/jquery-validation/js/jquery.validate.js" type="text/javascript"></script>
<script src="${request.getContextPath()}/Public/assets/global/plugins/jquery-validation/js/localization/messages_zh.min.js" type="text/javascript"></script>
<script src="${request.getContextPath()}/Public/assets/global/plugins/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
<script src="${request.getContextPath()}/Public/assets/global/plugins/bootstrap-hover-dropdown/bootstrap-hover-dropdown.min.js" type="text/javascript"></script>
<script src="${request.getContextPath()}/Public/assets/global/plugins/jquery-slimscroll/jquery.slimscroll.min.js" type="text/javascript"></script>
<script src="${request.getContextPath()}/Public/assets/global/plugins/jquery.blockui.min.js" type="text/javascript"></script>
<script src="${request.getContextPath()}/Public/assets/global/plugins/jquery.cokie.min.js" type="text/javascript"></script>
<script src="${request.getContextPath()}/Public/assets/global/plugins/uniform/jquery.uniform.min.js" type="text/javascript"></script>

<script src="${request.getContextPath()}/Public/assets/global/plugins/jquery.sparkline.min.js" type="text/javascript"></script>

<script src="${request.getContextPath()}/Public/assets/global/plugins/bootstrap-datepicker/js/bootstrap-datepicker.js" type="text/javascript"></script>

<script src="${request.getContextPath()}/Public/assets/global/scripts/metronic.js" type="text/javascript"></script>
<script src="${request.getContextPath()}/Public/assets/admin/scripts/layout.js" type="text/javascript"></script>
<script src="${request.getContextPath()}/Public/assets/admin/scripts/commonUtils.js" type="text/javascript"></script>

<!-- select2控件 -->
<script type="text/javascript" src="${request.getContextPath()}/Public/assets/global/plugins/select2/select2.js"></script>
<script type="text/javascript" src="${request.getContextPath()}/Public/assets/global/plugins/select2/select2_locale_zh-CN.js"></script>
<link href="${request.getContextPath()}/Public/assets/global/plugins/select2/select2.css" rel="stylesheet" type="text/css">

<script src="${request.getContextPath()}/Public/assets/global/plugins/bootstrap-datepicker/js/bootstrap-datepicker.js" type="text/javascript"></script>
<script src="${request.getContextPath()}/Public/assets/global/plugins/bootstrap-datepicker/js/bootstrap-datepicker.min.js" type="text/javascript"></script>
<script src="${request.getContextPath()}/Public/assets/global/plugins/bootstrap-datepicker/js/bootstrap-datepicker.zh-CN.min.js" type="text/javascript"></script>

<!-- 数据验证 -->
<script src="${request.getContextPath()}/Public/assets/global/plugins/jquery-validation/js/jquery.validate.js" type="text/javascript"></script>
<script src="${request.getContextPath()}/Public/assets/global/plugins/jquery-validation/js/localization/messages_zh.min.js" type="text/javascript"></script>
<script type="text/javascript" src="${request.getContextPath()}/Public/My97DatePicker/WdatePicker.js"></script>
<!-- 数字小数点后两位工具类 -->
<script type="text/javascript" src="${request.getContextPath()}/Public/js/common/util.js"></script>

<style type="text/css">
    *
    {
        font-size: 14px;
    }
    #dataForm label.error
    {
        color: Red;
        font-size: 13px;
        margin-left: 5px;
        padding-left: 16px;
        background:  left no-repeat;
    }
    .commonBtn{
    	margin: 0 5px;
    }
    .normalBtn{
    	border: 1px solid #C0C1B4; color:#555; background-color:#fff;
    }
    
.ttLbl .radio {
	padding-top: 0;
}
</style>
</head>
<body class="page-header-top-fixed">
<div class="page-header">
	<!--头部开始-->
	<#include "/include/top.html" />
	<!-- 头部信息结束 -->

	<!-- 头部菜单开始 -->
	<#include "/include/top_menu.html" />
	<!-- 头部菜单结束 -->
</div>
<!-- END HEADER -->
<div class="page-container">
	<div class="page-content">
		<div class="container-fluid">
			<!-- 当前位置提示开始 -->
			<ul class="page-breadcrumb breadcrumb">
				<li>
					<a href="#">首页</a><i class="fa fa-circle"></i>
				<li class="active">
					 撮合管理<i class="fa fa-circle"></i>
				<li class="active">
					 新建卖盘池
			</ul>
			<div class="row margin-top-10">
				<div class="col-md-12">
					<form class="form-horizontal" id="dataForm">
					<input type="hidden" in="only" name="only" value="${only}">
					<div >
						<p align="left" ><font size="4">选择产品:</font></p>
						<table >
						<tr>
						<td width="100px"></td>
						<#list prodList as pro>
						
						<td > <input type="button" onclick='commodity(${pro.id},"${pro.name}",this)'  name ="prodclass"  value="${pro.name}" class="btn commonBtn normalBtn" > </td>
						<#if pro_index%6==0 && pro_index!=0 >
						</tr>
						</#if>
						</#list>
						
						</table>
					
						</div>
						<table id="commtab">
						
						</table>
						
						<br></br>
						  <input type="hidden" name="prodId"  id="prodId" />
						  <input type="hidden" name="prodName" id="prodName" /> 
						  <div class="form-group">
						    <label  class="col-sm-2 control-label">企业名称</label>
						    <div class="col-sm-4">
						      <input  class="form-control" id="companyid"  name="companyid" style="width: 235px;height: 34px;" />
						    </div>
						   </div>
						   
						   <!-- 品目ID -->
						   <input type="hidden" id="itemId" value="${itemId}">
						  	 <!-- 新增报价人    2016年1月4日下午1:28:21 -->
						 	<div class="form-group">
								<label class="col-sm-2 control-label">报价人：</label>
								<div class="col-sm-1">
									<input class="form-control" width="100" id="offerer"
											name="offerer" value="${user.id}" style="width: 130px; height: 60px;" />
								</div>
							</div>
						   <input type="hidden" id="companyName" value=""> 
						   <!--   <div class="form-group">
						    <label  class="col-sm-2 control-label">商城用户名</label>
						    <div class="col-sm-2">
						      <input  class="form-control"  width="200" id="account"  name="account"/> 
						      <select class="form-control"  style="width: 250px" id="totalmallid"  name="totalmallid" onchange="viewContact(this)" >						      
						      </select>
						    </div>
						    <div id="" class="col-sm-2">
						      <p><span>联系人:</span><span id="contact1" style="color: RED"></span></p>
						    </div>
						    <div id="telephone" class="col-sm-2">
						      <p><span>电话：</span><span id="telephone1" style="color: RED"></span></p>
						    </div>
						    </div>-->
					 	  <#list itemAttrList as itemAttr>
							  	<div class="form-group">
							  		<input type="hidden" name="arrtName" value="${itemAttr.name}">
							  		<input type="hidden" name="fillmode" value="${itemAttr.fillmode}">
							  		<input type="hidden" name="ids" value="${itemAttr.id?c}">
								    <label  class="col-sm-2 control-label">${itemAttr.name}：</label>
								    <div class="col-sm-2">
								    	<!-- 填写方式  文本框 -->
									    <#if itemAttr.fillmode?? && itemAttr.fillmode==0>
									    	<input type="text" name="attrValue${itemAttr.id}" class="form-control" />
									    </#if>
									    <!-- 填写方式  下拉框-->
								     	<#if itemAttr.fillmode?? && itemAttr.fillmode==1>
								      		<select  class="form-control"  name="attrValue${itemAttr.id}">
								      		<#if itemAttr.mainproperty?? && itemAttr.mainproperty==0 >
								      		<option value="" >----请选择---</option>
								      		</#if>
								      			<#if itemAttr.optionsValue??>
					  								<#list itemAttr.optionsValue as optionsValue>
								      				<option value="${optionsValue!''}">${optionsValue!''}</option>
								      				</#list>
					  				  			</#if>
								      		<select>
								      		<#if itemAttr.mainproperty?? && itemAttr.mainproperty==1 >
								      		<font color="red">(*必填项)</font>
								      		</#if>
								      	</#if>
								      	<#if itemAttr.fillmode?? && itemAttr.fillmode==2>
									   		 <#if itemAttr.optionsValue??>
						  						<#list itemAttr.optionsValue as optionsValue>								      		
													<input type="checkbox"  name="attrValue${itemAttr.id}" value="${optionsValue}" class="md-radiobtn" />
													<#if itemAttr.mainproperty?? && itemAttr.mainproperty==1 >
								      				<font color="red">(*必填项)</font>
								      				</#if>
													${optionsValue}
									      		</#list>
						  				 	 	</#if>
									    		</#if>						      	
								      	<!-- 填写方式  单选框-->
								        <#if itemAttr.fillmode?? && itemAttr.fillmode==3>
									    	<#if itemAttr.optionsValue??>
									    	<select  class="form-control" name="attrValue${itemAttr.id}">
									    	<#if itemAttr.mainproperty?? && itemAttr.mainproperty==0 >
								      		<option value="" >----请选择---</option>
								      		</#if>
						  					<#list itemAttr.optionsValue as optionsValue>
						  					
						  					<option value="${optionsValue}">${optionsValue}</option>
						  											      		
									      	</#list>	</select  >	
									      	<#if itemAttr.mainproperty?? && itemAttr.mainproperty==1 >
								      		<font color="red">(*必填项)</font>
								      		</#if>
						  				 	 </#if>
								    	</#if>
								    </div>
							  	</div>
						  </#list>
						  <div class="form-group">
						    <label  class="col-sm-2 control-label">库存：</label>
						    <div class="col-sm-4">
						      <input type="text" class="form-control" id="quantity" name="quantity" style="width: 235px;height: 34px;" onblur="if(value == 0 ){value=''}"/>
						    </div>
						  </div>
						  <div class="form-group">
						    <label  class="col-sm-2 control-label">仓库：</label>
						    <div class="col-sm-2">
						      <select class="form-control" id="wareProvince" name="wareProvince" onchange="selWareName();" style="width: 120px;height: 34px;">
						      	<option value="">请选择省份</option>
								    	<#list arealist as area>
								    			<option value="${area.id}">${area.name}</option>
								    	</#list>
						      </select>
						    </div>    
						    <div class="col-sm-2">
						      <!-- <select class="form-control" id="wareId" name="wareId" style="width: 120px;height: 34px;">
				    		  </select> -->
				    		  <input class="form-control" id="wareId" name="wareId">
						    </div>						 
						  </div>
						  <div class="form-group">
						    <label  class="col-sm-2 control-label">价格：</label>
						    <div class="col-sm-4">
						      <input type="text" class="form-control" id="price" name="price" style="width: 235px;height: 34px;"  onblur="if(value == 0 ){value=''}"/>
						    </div>
						  </div>
						  <div class="form-group">
						    <label  class="col-sm-2 control-label">起订量：</label>
						    <div class="col-sm-2">
						       <input type="text" class="form-control"  value="1"  name="moq" id="moq"
						       	onfocus="if(value == 1){value=''}"   
                				onblur="if(value==''){value=1}"
                				onblur="if(value == 0 ){value=1}"
                				/>
                				
						    </div>
						    <div class="col-sm-2">
						   		  <span class="changeUnit">吨</span>，超出部分按
						    </div>
						    <div class="col-sm-2">
						     
						      <input value="1"  name="outmoq"  id="outmoq"
						       	onfocus="if(value == 1){value=''}"   
                				onblur="if(value == 0 ){value=1}"
						      type="text">
						    </div>
						    <div class="col-sm-2">
						     	（<span class="changeUnit">吨</span>）整数倍递增
						    </div>
						  </div>
						    <div class="form-group">
						    <label  class="col-sm-2 control-label">磅差(‰)：</label>
						    <div class="col-sm-2">
						       <input type="text" value="2"  onblur="if(value == 0 ){value=2}" class="form-control" id="pounddiff" name="overflow">
						    </div>
						  </div>
						   <!--<div class="form-group">
					     	<label  class="col-sm-2 control-label">交货方式：</label>
							    <div class="col-sm-2">
							    	<select class="form-control" id="delivery"  name="delivery">
							    		<option value="1" selected="selected">卖方送货</option>
							       		<option value="2">买方自提</option>
							    	</select>
							    </div>
					   		</div> -->
						    <div class="form-group">
								<label class="col-sm-2 control-label">交货方式：</label>
								<div class="col-sm-1">
									<label class="ttLbl"><input type="radio"class="form-control" name="delivery" 
										value="2" checked="checked"> 买方自提</label>
								</div>
								<div class="col-sm-1">
									<label class="ttLbl"><input type="radio"class="form-control" name="delivery" 
										value="1"> 卖方送货</label>
								</div>
							</div>
						  
						  
						  	<!-- <div class="form-group">
							    <label  class="col-sm-2 control-label">结算方式：</label>
							    <div class="col-sm-2">
							       <select class="form-control"  id="paytype" name="paytype">
							    		<option value="1" selected="selected">现款现汇</option>
							       		<option value="2">银行承兑</option>
							       		<option value="3">安全支付</option>
							    	</select>
							    </div>
						  	</div> -->
						  	
						  	<div class="form-group">
								<label class="col-sm-2 control-label">结算方式：</label>
								<div class="col-sm-1">
									<label class="ttLbl"><input type="radio" class="form-control" name="paytype" 
									value="1" checked="checked">现款现汇</label>
								</div>
								<div class="col-sm-1">
									<label class="ttLbl"><input type="radio" class="form-control" name="paytype" 
									value="2"> 银行承兑</label>
								</div>
								<div class="col-sm-1">
									<label class="ttLbl"><input type="radio" class="form-control" name="paytype" 
										value="3"> 安全支付</label>
								</div>
							</div>
							
						    <!-- <div class="form-group">
						    <label  class="col-sm-2 control-label">付款方式：</label>
						    <div class="col-sm-2">
						    	<select class="form-control" id="receipttype"  name="receipttype">
						    		<option value="1" selected="selected">款到发货</option>
						       		<option value="2">货到付款</option>
						    	</select>
						    </div> -->
						    
			    		<div class="form-group">
							<label class="col-sm-2 control-label">付款方式：</label>
							<div class="col-sm-1">
								<label class="ttLbl"><input type="radio"class="form-control" name="receipttype" 
								value="1" checked="checked">款到发货</label>
							</div>
							<div class="col-sm-1">
								<label class="ttLbl"><input type="radio" class="form-control" name="receipttype" 
								value="2"> 货到付款</label>
							</div>
						</div>
						  
					      <div class="form-group">
						    <label  class="col-sm-2 control-label">交货日期：</label>
						    <div class="col-sm-2">
						       <input type="text" class="form-control" id="deliverytime"   onClick="WdatePicker()" name="deliverytime">
						    </div>
						  </div>
						   
						  <div class="form-group">
						    <label  class="col-sm-2 control-label">计量单位：</label>
						    <div class="col-sm-4">
						      <select  class="form-control" id="unit" name="unit" style="width: 235px;height: 34px;" >
						      	<option value="0" selected="selected">吨</option>
						      	<option value="1">千克</option>
						      </select>
						    </div>
						  </div>
						  <div class="form-group">
						    <label  class="col-sm-2 control-label">优先级：</label>
						    <div class="col-sm-4">
						      <select  class="form-control" id="priority" name="priority" style="width: 235px;height: 34px;" >
						      	<option value="0">高</option>
						      	<option value="1">中</option>
						      	<option value="2" selected="selected">低</option>
						      </select>
						    </div>
						  </div>
						  <div class="form-group">
						    <div class="col-sm-offset-2 col-sm-10">
						    	<button id="notSavetButton"  onclick="javascript :history.back(-1);" type="button" class="btn  green pull-left">
									返回 <i class="m-icon-swapright m-icon-white"></i>
								</button>
								
						      	<button type="button"  id="savetButton" class="btn green pull-center">
									新建<i class="m-icon-swapright m-icon-white"></i>
								</button>
								
								<button id="savetButtonfabu" type="button" class="btn  green pull-center">
									发布到商城 <i class="m-icon-swapright m-icon-white"></i>
								</button>
								<!-- <button id="savetButtonfabu" type="button" class="btn  green pull-center">
									新建 <i class="m-icon-swapright m-icon-white"></i>
								</button> -->
						    </div>
						  </div>
						</form>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>

<!-- 底部开始 -->
<#include "/include/foot.html" />
<!-- 底部结束 -->
</body>
<script>
	
	jQuery(document).ready(function() {
		//交货默认日期为当天
		var d = new Date();
	    var s = d.getFullYear().toString() + "-"+addzero(d.getMonth() + 1) +"-"+ addzero(d.getDate());
	    $('#deliverytime').val(s);
	    function addzero(v) {
     		if (v < 10) return '0' + v;return v.toString();
     	}
	    //品目银,在新建卖盘的时候默认计量单位为千克
	    if ($("#itemId").val() == 26288) {
			$(".changeUnit").text("千克");
			$("#unit").val("1").selected = true;
		}
		$(".control-label").css("text-align","center");
		$("#unit").change(function(){
			$(".changeUnit").each(function(index, element){
				$(element).text($("#unit :selected").text());
			});
		});
		
		 //商城
		 $("#account").empty();
			$.ajax({
				url : "${request.getContextPath()}/dealMake/queryCompany.do",
				type : "post",
				dataType:"json",
				async: false,
				data :{"companyName":$("#companyNm").val()}, //联动查询的字符
				success : function(data) {
		 		var jsonData = eval(data);//接收到的数据转化为JQuery对象，由JQuery为我们处理 
				$("#account").append("<option value=''>--请选择--</option>");
				$.each(jsonData, function(index, item) {
					$("#account").append(
							"<option value='"+item.userid+"'myAttr1='"+item.truename+"'myAttr2='"+item.mobile+"'>" + item.account + "</option>");
				}); 
			}
		});
			
	   	$("#companyid").select2({
		   language: "zh_CN",
           placeholder: "关键字搜索公司",//文本框的提示信息
           minimumInputLength: 0,//至少输入n个字符，才去加载数据
           allowClear: true, //是否允许用户清除文本信息
           /* multiple:true,//多选属性 */
           ajax: { // instead of writing the function to execute the request we use Select2's convenient helper
        	   url : "${request.getContextPath()}/dealMake/queryCompanyByNm.do",
               dataType: 'json',//接收的数据类型
               type : "post",
               data: function (term, page) {//在查询时向服务器端传输的数据
                   return {
                       companyName: term, //联动查询的字符
                       page: 10 //一次性加载的数据条数
                   };
               },
               results: function (data, page) { // parse the results into the format expected by Select2.
                   // since we are using custom formatting functions we do not need to alter remote JSON data
                   var realNames = new Array();    
                        for (var i = 0; i < data.length; i++) {
                             realNames.push({id: data[i].id, text: data[i].name});
                      }
                   return {results: realNames};
               }
           },
           formatResult: resultFormatResult, // omitted for brevity, see the source of this page
           formatSelection: resultFormatSelection_1,  // omitted for brevity, see the source of this page
           dropdownCssClass: "bigdrop", // apply css that makes the dropdown taller
           escapeMarkup: function (m) { return m; } // we do not want to escape markup since we are displaying html in results
      	 });
	   
	   
	   Metronic.init(); // init metronic core componets
	   Layout.init(); // init layout
	   
	   selWareName();
	   
	 //小数点后两位check
		checkNum($('#price'));
		checkNum5($('#quantity'));
		checkNum5($('#moq'));
		checkNum5($('#outmoq'));
	});
	recordDate();
	//初始化日期
	function recordDate() {
		var nowDate = new Date();
        //$('#date-picker').attr("date-date",nowDate.getFullYear()+"/"+parseInt(nowDate.getMonth()+1)+"/"+nowDate.getDate());
        $('.date-picker').datepicker({
    	    autoclose: true	   
    	});
        
        
	}
	
	//新建不发布
	$("#savetButton").bind("click",function(){
		if($("#prodId").val()==null ||""==$("#prodId").val()){
			alert("请选择产品");
			return ;
		}
		var  num=/^[0-9]+([.]{1}[0-9]+){0,1}$/;
		var quantity=Number($("#quantity").val());
		console.log('1库存:'+quantity);
		var price=Number($("#price").val()).toFixed(2);
		var pounddiff=$("#pounddiff").val();
		var outmoq=$("#outmoq").val();
		var moq=Number($("#moq").val());
		var offerer = $("#offerer").val();
		
		if(!num.test(quantity) || quantity<=0 ){
			alert("库存必须大于0的数");
			return ;
			
		}
		
		if (offerer == null || offerer == '') {
			alert("请选择报价员 ");
			return;
		}
		
		if(!num.test(price) || price<=0 ){
			alert("价格必须大于0的数");
			return ;
			
		}
		if(!num.test(moq) || moq<=0 ){
			alert("起订量必须大于0");
			return ;
			
		}
		if(moq>quantity ){
			alert("起订量必须小于库存");
			return ;
			
		}
		
		var num1=/[0-9]*[1-9][0-9]*/;
		if(!num1.test(outmoq) || outmoq<=0){
			alert("递增量必须为正整数");
			return ;
			
		}
		if(outmoq>quantity ){
			alert("递增量必须小于库存");
			return ;
			
		}
		
		if(!num.test(pounddiff) || pounddiff<=0){
			alert("磅差必须大于0的数");
			return ;
			
		}
		
		if(!$("#dataForm").validate({
			//数据验证
			rules:{
				prodId:"required",
				companyid:"required",
				wareName:"required" ,
				wareProvince:"required",
				wareId:"required",				
				priority:"required",
				unit:"required",
				prodId:"required",
				prodName:"required",
				deliverytime:"required",
			}
		
		}).form()){
			return;
		} 

		var paytype = $("input[name='paytype']:checked").val();
		if(paytype==3){
			//安全支付 
			var customerId=$("#companyid").val();
			$.ajax({
				url : "${request.getContextPath()}/dealMake/checkUserPay.do",
				type : "post",
				dataType:"json",
				async: false,
				data :{"customerId":customerId}, //联动查询的字符
				success : function(data) {
					if(data == 1){
						alert("这家企业没有有色网商城支付账号，无法进行安全支付！");
					} else {
						addSellPoolFun();
					}
				}
			});
			return false;
		} else {
			addSellPoolFun();
		}
		
	});
	
	//新建并发布
	$("#savetButtonfabu").bind("click",function(){
		if($("#prodId").val()==null ||""==$("#prodId").val()){
		
			alert("请选择产品");
			return ;
		}
		var  num=/^[0-9]+([.]{1}[0-9]+){0,1}$/;
		var quantity=$("#quantity").val();
		var price=Number($("#price").val()).toFixed(2);
		var pounddiff=$("#pounddiff").val();
		var outmoq=$("#outmoq").val();
		var moq=$("#moq").val();
		var offerer = $("#offerer").val();
		
		if(!num.test(quantity) || quantity<=0 ){
			alert("库存必须大于0的数");
			return ;
			
		}
		
		if (offerer == null || offerer == '') {
			alert("请选择报价员 ");
			return;
		}
		
		
		var num1=/[0-9]*[1-9][0-9]*/;
		if(!num1.test(outmoq) || outmoq<=0){
			alert("递增量必须为正整数");
			return ;
			
		}
		if(!num.test(pounddiff) || pounddiff<=0){
			alert("磅差必须大于0的数");
			return ;
			
		}
		
		if(!$("#dataForm").validate({
			//数据验证
			rules:{
				prodId:"required",
				companyid:"required",
				wareName:"required" ,
				wareProvince:"required",
				wareId:"required",				
				priority:"required",
				unit:"required",
				prodId:"required",
				prodName:"required",
				deliverytime:"required",
			}
		
		}).form()){
			return;
		} 
	
		var paytype = $("input[name='paytype']:checked").val()
		if(paytype==3){
			var customerId=$("#companyid").val();
			$.ajax({
				url : "${request.getContextPath()}/dealMake/checkUserPay.do",
				type : "post",
				dataType:"json",
				async: false,
				data :{"customerId":customerId}, //联动查询的字符
				success : function(data) {
					if(data == 1){
						alert("这家企业没有有色网商城支付账号，无法进行安全支付！");
					} else {
						addSellPoolFunfabu();
					}
				}
			});
			return false;
		} else {
			addSellPoolFunfabu();
		}
	});
	
	
	
	function resultFormatResult(medata) {
        return medata.text; 
	} 
	      
	function resultFormatSelection(medata) {
        return medata.text; 
	}
	
	function resultFormatSelection_1(medata) {
		$("#companyName").val(medata.text);
        return medata.text; 
	}
	
	
	function selWareName(){
		var value = $("#wareProvince").val();
		$("#wareId").empty();
		if(value==-1){
			var ops =  document.getElementById("wareId").options;
			ops.length=0;
			ops.add(new Option("请选择仓库",""));
			return;
		}
		
		
		//仓库模糊搜索
		$("#wareId").select2({// 
			   language: "zh_CN",
		       placeholder: "搜索仓库",//文本框的提示信息
		       minimumInputLength: 0,//至少输入n个字符，才去加载数据
		       allowClear: true, //是否允许用户清除文本信息
		       ajax: { // instead of writing the function to execute the request we use Select2's convenient helper
		    	   url : "${request.getContextPath()}/dealMake/selWarehouseByAreaBlur.do",
		           dataType: 'json',//接收的数据类型
		           type : "post",
		           data: function (term, page) {//在查询时向服务器端传输的数据
		               return {
		            	   wareName:term, //联动查询的字符
		            	   areaId : value,
		            	   companyName:$("#companyName").val(),
		                   page: 10 //一次性加载的数据条数
		               };
		           },
		           results: function (data, page) { // parse the results into the format expected by Select2.
		               // since we are using custom formatting functions we do not need to alter remote JSON data
		               	var realNames = new Array();  
		               	var provinceName = $("#wareProvince").find("option:selected").text();
		               		for (var i = 0; i < data.length; i++) {
		                         realNames.push({id: data[i].id, text: data[i].name});
		                         
		                  }
		               return {results: realNames};
		           }
		       	},
		       	formatResult: resultFormatResult, // omitted for brevity, see the source of this page
		       	formatSelection: resultFormatSelection,  // omitted for brevity, see the source of this page
		       	dropdownCssClass: "bigdrop", // apply css that makes the dropdown taller
		       	escapeMarkup: function (m) { return m; } // we do not want to escape markup since we are displaying html in results
		    });
		
		
		/* $.ajax({
			url : "${request.getContextPath()}/dealMake/selWarehouseByArea.do",
			type : "post",
			dataType:"json",
			async: false,
			data :{"areaId":value},
			success : function(data) {
			 	var jsonData = eval(data);//接收到的数据转化为JQuery对象，由JQuery为我们处理 
				$("#wareId").append("<option value=''>--请选择--</option>");
				$.each(jsonData, function(index, item) {
					$("#wareId").append(
							"<option value='"+item.id+"'>" + item.name + "</option>");
				}); 
			}
		}); */
	}
	
	function  mall(){
		
		
		var companyName=null;
		$.ajax({
			url : "${request.getContextPath()}/dealMake/getcompanyName.do",
			type : "post",
			dataType:"json",
			async: false,
			data :{"id":$("#companyid").val()}, //联动查询的字符
			success : function(data) {
			
				companyName=data;
		}
		});
	
		 $("#totalmallid").empty();
			$.ajax({
				url : "${request.getContextPath()}/dealMake/queryCompany.do",
				type : "post",
				dataType:"json",
				async: false,
				data :{"companyName":companyName}, //联动查询的字符
				success : function(data) {
				 	var jsonData = eval(data);//接收到的数据转化为JQuery对象，由JQuery为我们处理 
					$("#totalmallid").append("<option >--请选择--</option>");
					$.each(jsonData, function(index, item) {
						$("#totalmallid").append(
								"<option value='"+item.userid+"'myAttr1='"+item.truename+"'myAttr2='"+item.mobile+"'>" + item.account + "</option>");
					}); 
				}
			});	
		
		
		
		
	}
	
	//下拉框选中触发
	function viewContact(object){
		 	var obj=document.getElementById("totalmallid");    
		    var index=obj.selectedIndex;   
		    var myAttr1=obj.options[index].getAttribute("myAttr1");//联系人
		    var myAttr2=obj.options[index].getAttribute("myAttr2");//电话
		    
		  //追加联系人数据
			document.getElementById("contact1").innerHTML = myAttr1;
			$("#contact").val(myAttr1);
			document.getElementById("telephone1").innerHTML = myAttr2;
	}
	
	function  commodity(prodId,prodName,obj){
		$("#prodId").val(prodId);
		$("#prodName").val(prodName);
		
		var prodclasss=document.getElementsByName("prodclass");
		$("input[name='prodclass']").removeClass("green");
		
		$(obj).addClass("green");
    }
	
	function   addSellPoolFun(){
		$.ajax({
			url : "${request.getContextPath()}/dealMake/addSellPool.do",
			type : "post",
			dataType:"json",
			async: false,
			data : $("#dataForm").serialize(),
			success : function(result) {
			   if(result.code=="success"){
				   		alert("新增成功 ！");
			      		window.location.href="${request.getContextPath()}/dealMake/sellOrder.do";
				}else if(result.code=="error"){
					//alert("已经添加过此卖盘池，请重新选择条件");
					alert("已经添加过此卖盘池");
					window.location.href="${request.getContextPath()}/dealMake/sellOrder.do";
		   		}else if(result.code=="REPEAT"){
		   			alert("买盘同步商城接口调用异常");
		   			window.location.href="${request.getContextPath()}/dealMake/sellOrder.do";
		   		}else if (result.code=="CFKH") {
		   			alert("商品不存在");
		   			window.location.href="${request.getContextPath()}/dealMake/sellOrder.do";
				}else if(result.code=="SELCOUNT"){
					alert("已存在企业,商品  ,数量和价格 相同的买盘池记录");
					window.location.href="${request.getContextPath()}/dealMake/sellOrder.do";
				}else{
					alert(result);
					window.location.href="${request.getContextPath()}/dealMake/sellOrder.do";
				}
			   }
		});
		
	}
	function   addSellPoolFunfabu(){
		$.ajax({
			url : "${request.getContextPath()}/dealMake/addSellPool.do?flag=fabu",
			type : "post",
			dataType:"json",
			async: false,
			data : $("#dataForm").serialize(),
			success : function(result) {
			   if(result.code=="success"){
				   		alert("新增成功 ！");
			      		window.location.href="${request.getContextPath()}/dealMake/sellOrder.do";
				}else if(result.code=="error"){
					alert("已经添加过此卖盘池");
					window.location.href="${request.getContextPath()}/dealMake/sellOrder.do";
		   		}else if(result.code=="REPEAT"){
		   			alert("买盘同步商城接口调用异常");
		   			window.location.href="${request.getContextPath()}/dealMake/sellOrder.do";
		   		}else if (result.code=="CFKH") {
		   			alert("商品不存在");
		   			window.location.href="${request.getContextPath()}/dealMake/sellOrder.do";
				}else if(result.code=="SELCOUNT"){
					alert("已存在企业,商品  ,数量和价格 相同的买盘池记录");
					window.location.href="${request.getContextPath()}/dealMake/sellOrder.do";
				}else{
					alert(result);
					window.location.href="${request.getContextPath()}/dealMake/sellOrder.do";
				}
			   }
		});
		
	}
	
	
	
	$("#offerer").select2({
		 language: "zh_CN",
	       placeholder: "搜索报价员",//文本框的提示信息
	       minimumInputLength: 0,//至少输入n个字符，才去加载数据
	       allowClear: true ,//是否允许用户清除文本信息
	       ajax: { // instead of writing the function to execute the request we use Select2's convenient helper
	    	   url : "${request.getContextPath()}/business/offererList.do",
	           dataType: 'json',//接收的数据类型
	           type : "post",
	           data: function (term, page) {//在查询时向服务器端传输的数据
	               return {
	            	   userName:term, //联动查询的字符
	                   page: 10 //一次性加载的数据条数
	               };
	           },
	           results: function (data, page) { // parse the results into the format expected by Select2.
	               // since we are using custom formatting functions we do not need to alter remote JSON data\
	               var realNames = new Array();    
	                    for (var i = 0; i < data.length; i++) {
	                         realNames.push({id: data[i].id, text: data[i].name});
	                         
	                  }
	               return {results: realNames};
	           }
	       	},
	       	initSelection: function(element, callback) {//加载初始化
				var userId = $("#offerer").val();
				if (userId != "") {
					$.ajax("${request.getContextPath()}/business/initOfferer.do").done(function(data) { 
						callback({id:data.id,text:data.name}); 
					});
				}
			},
	       	formatResult: resultFormatResult, // omitted for brevity, see the source of this page
	       	formatSelection: resultFormatSelection,  // omitted for brevity, see the source of this page
	       	dropdownCssClass: "bigdrop", // apply css that makes the dropdown taller
	       	escapeMarkup: function (m) { return m; } // we do not want to escape markup since we are displaying html in results
	});
	
</script>
</html>

